package com.test.coder;

import com.test.message.Message;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class Encoder extends MessageToByteEncoder<Object> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        Message m = (Message) msg;
        out.writeByte(m.getHead());
        out.writeByte(m.getFunCode());
        out.writeShort(m.getMessageLength());
        out.writeBytes(m.getMessageData());
        out.writeShort(m.getCrc());
    }
}
